//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    serviceItem: [],
    show_nav: "h_nav"

  },
  escOrder:function(e){
    var that = this;
    var _ism = wx.getStorageSync("_ism");
    var member_id = wx.getStorageSync("_hairdresser_id");
    wx.showModal({
      title: '退单',
      content: '确定退单前请联系用户!',
      success:function(sm){
        if(sm.confirm){
          wx.request({
            url: app.globalData.api_url + "index.php?ac=hapi&ts=order_opt",
            data: { 
              order_id: e.currentTarget.dataset.orderId,
              ism: _ism,
              hid: member_id,
              orderStat: 0,
              stat: 2
             },
            method: "GET",
            header: { 'content-type': 'application/json' },
            success: function (res) {
              that.setData({
                orderList: res.data
              })
              console.log(res.data);
            }

          })
        }else{
          console.log('已取消')
        }
      }
    })


    
  },
  show_nav: function (e) {
    var that = this;
    that.setData({
      show_nav: 'Haircut_nav'
    });
  },
  completeOrder: function (e) {
    console.log(e)
    var that = this;
    var _ism = wx.getStorageSync("_ism");
    var member_id = wx.getStorageSync("_hairdresser_id");
    wx.showModal({
      title: '完成订单',
      content: '确认用户已到店服务完成?',
      success: function (sm) {
        if (sm.confirm) {
          wx.request({
            url: app.globalData.api_url + "index.php?ac=hapi&ts=order_opt",
            data: { 
              order_id: e.currentTarget.dataset.orderId,
              ism: _ism,
              hid: member_id,
              orderStat: 0,
              stat:1
            },
            method: "GET",
            header: { 'content-type': 'application/json' },
            success: function (res) {
              that.setData({
                orderList: res.data
              }) 
              console.log(res)
            }
            
          })
        } else {
          console.log('已取消')
        } 
      }
    })



  },
  onLoad: function (e) {
    var that = this;
    var _ism = wx.getStorageSync("_ism");
    var member_id = wx.getStorageSync("_hairdresser_id");
     var pages = getCurrentPages();
                  var prevPage = pages[pages.length - 2]; 
                  prevPage.setData({
                    show_nav: 'h_nav'
                  });

    //调用应用实例的方法获取全局数据
    that.setData({
      userInfo: wx.getStorageSync("userInfo"),
    })
    console.log(wx.getStorageSync("userInfo"))
      wx.showLoading({
        title: '加载中',
      }),
      wx.request({
      url: app.globalData.api_url + "index.php?ac=hapi&ts=order_list",
        data: { 
          ism: _ism,
          hid: member_id,
          orderStat: 0,
         },
        header: { 'content-type': 'application/json' },
        success: function (res) {
          wx.hideLoading();
          that.setData({
            orderList: res.data
          }) 
        }

      })
      , setTimeout(function () {
        wx.hideLoading()
      }, 3000)
  }, 
 

})
